/*
 *    Copyright (c) 2018-2025, cycas-ui All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the cycas-ui_cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cycas-ui (cycas-ui@gmail.com)
 */
import {getDetails} from '@/api/sys/user'

const validateUsername = (rule, value, callback) => {
  if (!value) {
    return callback(new Error('请输入用户名'))
  }
  getDetails(value).then(response => {
    if (window.boxType === 'edit') callback()
    let result = response.data.data
    if (result !== null) {
      callback(new Error('用户名已经存在'))
    } else {
      callback()
    }
  })
}

// 设置密码校验规则
const checkPassword = (rule, value, callback) => {
  if (window.boxType === 'edit') {
    return callback()
  }
  if (!value) {
    callback(new Error('请输入密码'))
  } else {
    callback()
  }
}

// 设置手机号的验证规则
const checkPhone = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入联系方式'))
  } else {
    const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
    if (reg.test(value)) {
      callback()
    } else {
      return callback(new Error('请输入正确的电话'))
    }
  }
}

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuWidth:'120px',
  menuAlign: 'center',
  searchMenuSpan: 6,
  menu: false,
  editBtn: false,
  delBtn: false,
  addBtn: false,
  align: 'center',
  height: '290px',//表格高度
  // calcHeight: 'auto',//表格高度差（主要用于减去其他部分让表格高度自适应）
  // maxHeight: '280px',//表格最大高度
  column: [{
    // fixed: true,
    label: 'id',
    prop: 'userId',
    span: 24,
    hide: true,
    editDisplay: false,
    addDisplay: false
  }, {
    label: '用户名',
    prop: 'username',
    search: true,
    span: 24
  }, {
    label: '姓名',
    prop: 'personName',
    search: false,
    span: 24
  }, {
    label: '手机号',
    prop: 'phone',
    search: false,
    span: 24
  },{
    label: '用户类型',
    prop: 'userType',
    border: true,
    span: 20,
    dicData: [{
      label: '超级管理员',
      value: -99
    }, {
      label: '租户管理员',
      value: -1
    }, {
      label: '普通用户',
      value: 0
    }]
  },{
    label: '性别',
    prop: 'gender',
    border: true,
    span: 4,
    dicData: [{
      label: '男',
      value: 0
    }, {
      label: '女',
      value: 1
    }]
  },{
    label: '状态',
    prop: 'isLock',
    border: true,
    span: 4,
    dicData: [{
      label: '正常',
      value: 0
    }, {
      label: '锁定',
      value: 1
    }]
  },{
    width: 150,
    label: '创建时间',
    prop: 'createTime',
    format: 'yyyy-MM-dd HH:mm:ss',
    span: 24
  }]
}
